package com.sinodata.bsm.center.engine.notify.impl;

import java.text.SimpleDateFormat;

import org.apache.log4j.Logger;

import com.sino.uam.entity.UserInfo;
import com.sinodata.bsm.center.bean.EventTypeBean;
import com.sinodata.bsm.center.bean.ResBean;
import com.sinodata.bsm.center.engine.notify.NotifyMode;
import com.sinodata.bsm.common.constants.EventConstants;
import com.sinodata.bsm.common.vo.Event;
import com.sinodata.bsm.common.vo.Notify;

/**
 * 
 * <p>
 * Description: 电话通知实现类
 * </p>
 *
 * @author liulibo
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-8-9 PM 4:11:24      liulibo        1.0         To create
 * </p>
 *
 * @since 
 * @see
 */
public class TelNotifyModeImpl implements NotifyMode {

    private static final Logger logger = Logger.getLogger(TelNotifyModeImpl.class);

    public TelNotifyModeImpl() {

    }

    /*
     * (non-Javadoc)
     * @see com.sinodata.bsm.center.engine.notify.NotifyMode#createNotifyMessage(com.sinodata.bsm.common.vo.Event)
     */
    @Override
    public String createNotifyMessage(Event eventValue) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String date = formatter.format(eventValue.getOccurTime());
        StringBuilder strBuilder = new StringBuilder();
        strBuilder.append("[" + EventConstants.getLevelDesc(eventValue.getLevel()) + "]");
        String notifyMessage = eventValue.getMsg();
        //发送通知消息时计算实时的通知信息 //暂且不启用
        //        if (eventValue.getMsgExpr() != null && !eventValue.getMsgExpr().equals("")) {
        //            try {
        //                Object msg = Expressions.eval(eventValue.getMsgExpr());
        //                if (msg != null && msg instanceof String) {
        //                    notifyMessage = (String) msg;
        //                }
        //            } catch (Exception e) {
        //                logger.error("failed to calc real-time alarm message,used original alarm message", e);
        //            }
        //        }
        strBuilder.append(notifyMessage);
        strBuilder.append(" ");
        strBuilder.append(date);
        return strBuilder.toString();
    }

    /*
     * (non-Javadoc)
     * @see com.sinodata.bsm.center.engine.notify.NotifyMode#createResumeMessage(com.sinodata.bsm.common.vo.Event)
     */
    @Override
    public String createResumeMessage(Event eventValue) {
        ResBean res = ResBean.get(eventValue.getResId());
        EventTypeBean type = EventTypeBean.get(eventValue.getEventTypeId());
        StringBuilder strBuilder = new StringBuilder();
        strBuilder.append("[恢复]");//[恢复] {192.168.92.124} {linux主机11} {xx类别} {紧急} 2011-08-09 12:00
        strBuilder.append("[" + res.res().getIp() + "] [");
        strBuilder.append(res.res().getName() + "] [");
        strBuilder.append(type.eventType().getName() + "] [");
        strBuilder.append(EventConstants.getLevelDesc(eventValue.getLevel()));
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String date = formatter.format(eventValue.getOccurTime());
        strBuilder.append("] ");
        strBuilder.append(date);
        return strBuilder.toString();
    }

    /*
     * (non-Javadoc)
     * @see com.sinodata.bsm.center.engine.notify.NotifyMode#getNotifyDestination(com.sino.uam.entity.UserInfo)
     */
    @Override
    public String getNotifyDestination(UserInfo userInfo) {
        return userInfo.getMobileTel();
    }

    /* (non-Javadoc)
     * @see com.sinodata.bsm.center.engine.notify.NotifyMode#createMsg()
     */
    @Override
    public String createMsg(Notify notify) {
        return null;
    }

}